# -*- coding: utf-8 -*-


# cmap2owl -- Helper application to convert from concept maps to OWL ontologies
# Copyright (c) 2008-2013  Rodrigo Rizzi Starr
#  
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#  
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#  
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


'''
A class implementing an action item for an element

@author: Rodrigo Rizzi Starr
@copyright: Copyright © 2008-2013 Rodrigo Rizzi Starr
@license: MIT License
@contact: rodrigo.starr@gmail.com
'''


from __future__ import division
import sys

# GTK+ imports
import pygtk
if not sys.platform == 'win32':
    pygtk.require('2.0')
try:
    import gtk
    import gtk.glade
    import gobject 
except:
    sys.exit(1)

class Action(gtk.MenuItem):
    """Implements a question answering structure which signalizes when an
        an answer was given.
        
        As a matter of fact, this class is both the view and the model of the
          question, so it is not a very good design. Maybe I refactor it latter
        """
    
    __gsignals__ = {"on-answer" : (gobject.SIGNAL_RUN_LAST,
                                   gobject.TYPE_NONE,
                                   ())
                    }
    
    def __init__(self, db = None, question="", action=""):
        gtk.MenuItem.__init__(self, None)
        
        self.db = db
        self.question = question
        self.action = action
        
        if "" == self.question or None == self.question:
            label = gtk.Label("There is no action for the current element")
            self.set_sensitive(False)
        else:
            label = gtk.Label(self.question)
            label.set_line_wrap(True)
            label.set_property("width-request", 340)
#            label.set_property("xalign", 0.1)
            label.set_justify(gtk.JUSTIFY_CENTER)
        
        self.connect("activate", self.activate)
        self.add(label)
        
        self.show_all()
    
    def activate(self, widget = None):
        "Does something when the menu is activated"
        if None != self.db:
            self.db.assertz(self.action)
        self.emit("on-answer")
            
            
            
            
